<?php
/**
 * 商品订单统计
 * @author jc
 * @date 19/9/11
 *
 */
namespace app\statis\model;

use app\common\model\CoreOrder;
use app\common\model\Product;
use think\Exception;

class CoreOrderModel extends CoreOrder
{
    /**
     * 获取时间区段内的有效的订单商品
     *
     * @param $start
     * @param $end
     * @param int $address_type 配送方式 [1为物流，2为自提, 3为全部]
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getProductByTime($start, $end, $address_type = 3)
    {
        $model = $this->with(['product'])
            ->where(['status' => [self::STATUS_0, self::STATUS_9]])
            ->where('create_time', 'between', [$start, $end]);

        if ($address_type == 1) {
            $model = $model->where(['self' => 0]);
        } elseif ($address_type == 2) {
            $model = $model->where(['self' => 1]);
        }

        return $list = $model->select()->toArray();
    }

    /**
     * 根据时间获取
     * 所有的订单数据
     *
     * @param $start
     * @param $end
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getOrderByTime($start, $end)
    {
        return $order_data = $this
            ->where('create_time', 'between', [$start, $end])
            ->select()
            ->toArray();
    }

}